package org.glut.friendsService.controller;

import org.glut.friendsService.entity.Friends;
import org.glut.friendsService.service.IFriendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  前端控制器
 *
 * @author qjc
 * @since 2024-08-16 12:29
 */
@RestController
@RequestMapping("/friends")
public class FriendsController {
    @Autowired
    private IFriendsService friendService;

    // 获取好友列表
    @GetMapping("/list")
    public List<Friends> getFriends(@RequestParam("userId") Integer userId) {
        return friendService.getFriendsByUserId(userId);
    }

    // 添加好友
    @PostMapping("/add")
    public String addFriend(@RequestParam("userId") Integer userId, @RequestParam("friendId") Integer friendId) {
        boolean success = friendService.addFriend(userId, friendId);
        return success ? "添加成功" : "好友已存在";
    }

    // 删除好友
    @DeleteMapping("/delete")
    public String deleteFriend(@RequestParam("userId") Integer userId, @RequestParam("friendId") Integer friendId) {
        boolean success = friendService.deleteFriend(userId, friendId);
        return success ? "删除成功" : "好友不存在";
    }
}
